#ifndef _SNAKE_H_
#define _SNAKE_H_
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<conio.h>
#include<Windows.h>
#include<stdbool.h>


#define WIDE 60
#define HIGH 20
#define MAX_OBSTACLES 50

struct BODY{
    int X;
    int Y;
};

//定义蛇对象
struct SNAKE{
    struct BODY body[WIDE*HIGH];
    int size;
}snake;

//定义食物对象
struct FOOD{
    int X;
    int Y;
}food;

//初始分数
int score=0;

typedef enum{
    DIR_UP,DIR_DOWN,DIR_LEFT,DIR_RIGHT
}Direction;

struct GameState{
    Direction currentDir;
    Direction lastDir;
    bool gameOver;
    int score;
    int speed;
    int level;
};

struct GameState game;

typedef struct{
    int X;
    int Y;
}Obstacle;

Obstacle obstacles[MAX_OBSTACLES];

int kx=0;
int ky=0;

int lastX=0;
int lastY=0;

int sleepSecond=500;

bool isPaused=false;

int obstacleCount=0;

typedef struct UserNode {
    char id[50];  
    int score;
    struct UserNode* next;
}UserNode;

UserNode *head=NULL;

UserNode* curentUser=NULL;

void showPauseScreen();
void resumeGameScreen();
void initUser();
void initSnake();
void initFood();
void initUI();
void initObstacle();
void updateLevel();
void handleInput();
void moveSnake();
void checkCrush();
void playGame();
void initWall();
void showScroe();
void showLevalInfo();

void initUserSystem();
UserNode* createUserNode(const char* id);
UserNode* findUser(const char* id);
void initUser();
void updateUserScore(int newScore);
void saveUserScores();
void loadUserScores();
void showScoreRanking();
void gameOver();


#endif
